<template>
  <div style="color: red">面向对象</div>
  <br />
  <div>
    面向对象的特点：继承，封装，多态(重载，重写，子类可以重写父类的方法)
  </div>
</template>

<script setup lang="ts" name="Hoisting">
class Shape {
  width: number;
  height: number;
  constructor(width: number, height?: number) {
    this.width = width;
    this.height = height;
  }
  getArea() {
    return this.width * this.height;
  }
  text() {
    return 111;
  }
}

class Circle extends Shape {
  radius: number;
  constructor(radius: number, width?: number, height?: number) {
    super(width, height);
    this.radius = radius;
  }
  getArea() {
    // const area=().toFixed(2)
    return Math.PI * this.radius ** 2;
  }
}

class Square extends Shape {
  constructor(width: number, height: number) {
    super(width, height);
  }
}

class Ellipse extends Shape {
  constructor(width: number, height: number) {
    super(width, height);
  }
  getArea() {
    return Math.PI * this.width * this.height;
  }
}
const circle = new Circle(5);
console.log("圆形的面积为：", Number(circle.getArea().toFixed(2)));
const square = new Square(4, 5);
console.log("矩形面积为：", square.getArea());
const ellipse = new Ellipse(4, 9);
console.log("椭圆形的面积为：", Number(ellipse.getArea().toFixed(2)));
console.log(ellipse);

const obj = {
  name: "Quina",
  age: 26,
};
const obj1 = {
  name: "Quina",
  age: 26,
};
console.log(obj.hasOwnProperty("age")); //hasOwnProperty 判断属性名是否在某个对象上
console.log(Object.prototype.isPrototypeOf(obj1));
console.log((obj as any).__proto__ == Object.prototype);

let o = new Object();
console.log(Object.prototype.isPrototypeOf(o)); // true  表示：在Object.prototype是否o的原型
</script>

<style scoped lang="scss"></style>
